import { fileURLToPath, URL } from "node:url";
import path from "path";
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
// https://vite.dev/config/
import UnoCSS from "unocss/vite";
export default defineConfig((mode) => {
  console.log("mode", mode);

  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [vue(), UnoCSS()],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      },
    },

    // 全局替换常量
    define: {
      _APP_NAME: '"DUQICHANG_NAME"',
    },
    server: {
      open: true,
      proxy: {
        // 代理 /dev-api 的请求
        [env.VITE_APP_BASE_API]: {
          changeOrigin: true,
          target: env.VITE_APP_API_URL,
          rewrite: (path) =>
            path.replace(new RegExp("^" + env.VITE_APP_BASE_API), ""),
        },
      },
    },
  };
});
